package com.Lixiaoqian.PartyHistoryMuseum.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.Lixiaoqian.PartyHistoryMuseum.base.MyApplication;

import java.io.File;

/**
 * Created by huangzhibo on 2017/9/19/019.
 * mail:1043202454@qq.com
 */

public class Utils {
    /**
     * 判断是否有网络
     * @return
     */
    public static boolean isNetworkAble(){
        ConnectivityManager connectivityManager = (ConnectivityManager) MyApplication.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager!=null){
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
            if (networkInfo!=null&&networkInfo.isConnected()){
                if (networkInfo.getState()==NetworkInfo.State.CONNECTED){
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 检查存在文件夹
     * @param dirPath
     * @return
     */
    public static boolean isFolder(String dirPath){
        File file = new File(dirPath);
        return file.isDirectory();
    }

    /**
     * 创建文件夹
     * @param dirPath
     */
    public static void createFolde(String dirPath){
        File file = new File(dirPath);
        file.mkdir();
    }

}
